# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=qt-creator

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
#_pre=rc1
#__pre=-rc1
_base_ver=3.1.2
pkgver=${_base_ver}${_pre}
pkgrel=2
pkgdesc='Cross-patform IDE (mingw-w64)'
url='http://qt-project.org'
install=qt-creator-${CARCH}.install
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
        "${MINGW_PACKAGE_PREFIX}-gcc"
        "${MINGW_PACKAGE_PREFIX}-make"
        "${MINGW_PACKAGE_PREFIX}-qbs")
makedepends=("${MINGW_PACKAGE_PREFIX}-clang")
options=('docs' 'staticlibs') # 'debug' '!strip'
optdepends=("${MINGW_PACKAGE_PREFIX}-gdb: for the debugger"
            "${MINGW_PACKAGE_PREFIX}-cmake: for cmake project support"
            "${MINGW_PACKAGE_PREFIX}-clang: for clang code model"
            #'openssh-askpass: for ssh support'
            #'git: for git support'
            #'mercurial: for mercurial support'
            #'bzr: for bazaar support'
            )
_pkgfqn="${_realname}-opensource-src-${_base_ver}${__pre}"
source=(#http://download.qt-project.org/development_releases/qtcreator/${_base_ver%.*}/${_base_ver}-${_pre}/${_pkgfqn}.tar.gz
        http://download.qt-project.org/official_releases/qtcreator/${pkgver%.*}/${pkgver}/${_pkgfqn}.tar.gz
        qt-creator-3.0.0-path-quote.patch
        qt-creator-3.1.0-Allow-static-clang-via-LLVM_STATIC-env-var.patch
        qt-creator-3.1.0-Allow-iOS-plugin-on-any-platform.patch)
noextract=(${_pkgfqn}.tar.gz)
sha256sums=('5c41d2303efa50d7dd37c370bb850c436d9b76f4152dc08f2d13ec8983ee0d2c'
            '26f9f487cd609091900a6d900ab5067023b4e4349e06f4477c80debbbd32ec6f'
            '606e66eae324312f168c543fd0a3bbfe78b35f4b1f592ad7a11c5b1b7a6c83ae'
            'a86fb90fa133be45a4c73e6cdf3f4c2fe726d46c6d00d258e67860e714bdc5ad')
prepare() {
  cd $startdir/
  [ -d ${srcdir}/${_pkgfqn} ] && rm -rf ${srcdir}/${_pkgfqn}
  tar -xzf ${_pkgfqn}.tar.gz -C $srcdir || true

  cd ${srcdir}/${_pkgfqn}
  patch -p0 -i ${srcdir}/qt-creator-3.0.0-path-quote.patch
  patch -p1 -i ${srcdir}/qt-creator-3.1.0-Allow-static-clang-via-LLVM_STATIC-env-var.patch
  patch -p1 -i ${srcdir}/qt-creator-3.1.0-Allow-iOS-plugin-on-any-platform.patch
  
  # Use system installed qbs
  rm -rf src/shared/qbs
}

build() {
  [ -d ${srcdir}/build-${MINGW_CHOST} ] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  export LLVM_INSTALL_DIR=${MINGW_PREFIX}
  export QBS_INSTALL_DIR=${MINGW_PREFIX}
  export LLVM_STATIC=1
  if check_option "debug" "y"; then
    _config_variant=debug
  else
    _config_variant=release
  fi
  ${MINGW_PREFIX}/bin/qmake.exe ../${_pkgfqn}/qtcreator.pro CONFIG+=${_config_variant}
  make
  make docs
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make INSTALL_ROOT="${pkgdir}${MINGW_PREFIX}" install
  make INSTALL_ROOT="${pkgdir}${MINGW_PREFIX}" install_docs
  
  install -Dm644 ${srcdir}/${_pkgfqn}/LGPL_EXCEPTION.TXT ${pkgdir}${MINGW_PREFIX}/share/licenses/qtcreator/LGPL_EXCEPTION.TXT
}

